<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="EN" lang="EN"
	dir="ltr">
<head>
<title>Moment Mobile Payments</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<meta http-equiv="imagetoolbar" content="no" />
<link rel="stylesheet"
	href="<%=request.getContextPath()%>/styles/layout.css" type="text/css" />
<script src="//code.jquery.com/jquery-1.9.1.js"></script>
<script src="<%=request.getContextPath()%>/js/pr.js"></script>
<script>
	$(function() {
		$('.office-title').click(function() {
			$(this).next('div').slideToggle();

			$(this).parent().siblings().children().next().slideUp();
			return false;
		});
		/**** new code ***/

	});
</script>
</head>
<body id="top">
	<%@include file="loggedinheader.jsp"%>
	<%@ page import="org.json.*"%>
	<%@ page import="com.moment.model.*"%>
	<%!String s[];%>
	<%
		System.out.println("Session name:="
				+ session.getAttribute("username"));
		if ((session.getAttribute("username") == null)
				|| (session.getAttribute("username") == "")) {
			response.sendRedirect("index.jsp");

		} else {
			String error = (String) session.getAttribute("error");
			System.out.println("Error=" + error);
			if (error != null && !error.equalsIgnoreCase("null")) {
	%>
	<div class="alert-box error">
		<span>error: </span><%=error%>
	</div>
	<%
		session.setAttribute("error", null);
			}
			String success = (String) session.getAttribute("success");
			System.out.println("Error=" + success);
			if (success != null && !success.equalsIgnoreCase("null")) {
	%>
	<div class="alert-box success">
		<span>success: </span><%=success%>
	</div>
	<%
		session.setAttribute("success", null);
			}
	%>


	<jsp:useBean id="userObj" class="com.moment.model.UserReg"
		scope="session" />
	<div class="wrapper col3">

		<div id="intro">
			<div id="logout">
				<a href="/MMP/LogoutController"><img
					src="<%=request.getContextPath()%>/images/logout.png" alt="Logout" /></a>
			</div>
			<div class="fl_left1">

				<div id="login1">
					<div class="imgl">
						<img alt="Embedded Image" height="128" width="128"
							src="data:image/jpeg;base64,<jsp:getProperty name="userObj" property="imagestr" />" />
					</div>
				</div>
				<div id="instrumentsmain">
					<div>
						<center>
							<h2>
								Welcome
								<jsp:getProperty name="userObj" property="name1" />
							</h2>
						</center>

					</div>
					<div id="login3">
						<%
							if (!userobj.equals(null)) {
									String memtype = userobj.getTypeofmember();
									if (memtype.equalsIgnoreCase("merchant")) {
						%>
						<h2>Make Payment Request</h2>
						<div id="login4">
							<div id="payment_div" style="padding: 0px 5px 10px 5px;">
								<form id="payment_form" name="payment_form"
									action="../PaymentRequestController" method="post">

									<div class="control-group">
										<label class="control-label" for="cnum">Customer
											Number</label><input type="text" maxlength="10" size="20" name="cnum" id="cnum" />
<span class="help-inline" style="display: none;">Please enter 10 digit mobile number</span>											
									</div>
											<div class="control-group">
									<label class="control-label" for="amount">Amount</label><input
										type="text" name="amount" id="amount"  maxlength="20"/> 
<span class="help-inline" style="display: none;">Please enter amount in number only</span>										
									</div>
									<hr/>								
										<input type="submit"
										class="myButton" name="submit" value="Make Request" />
								</form>
							</div>
						</div>
						<%
							}
								}
						%>
						<h2>Notifications</h2>

						<div id="login2">

							<div id="load_nots"></div>


						</div>




					</div>

					<div class="slide-toggle">
						<%
							WalletData walletobj = (WalletData) session
										.getAttribute("walletObj");

								try {
									JSONArray jArray = new JSONArray(walletobj.getInstru());
									s = new String[jArray.length()];
									for (int i = 0; i < jArray.length(); i++) {
										JSONObject json_data = jArray.getJSONObject(i);
										s[i] = json_data.getString("NickName");
						%>
						<div class="office-row">
							<h3 class="office-title"><%=s[i]%></h3>
							<div class="office">
								<div class="instruinner">
									<a href='javascript:void(0);' id='pay'
										onclick="pay('<%=s[i]%>')">Pay</a>
								</div>
								<div class="instruinner">
									<a href='javascript:void(0);' id='edit'
										onclick="edit('edit','<%=s[i]%>')">View</a>
									<!-- <a href='javascript:void(0);' id='editinstru' onclick="editinstrument('edit','<%=s[i]%>');">
								Edit</a> -->
								</div>
								<div class="instruinner">
									<a href='javascript:void(0);' id='received'
										onclick="showhistory('r','<%=s[i]%>');">Received</a>
								</div>
								<div class="instruinner">
									<a href='javascript:void(0);' id='paid'
										onclick="showhistory('p','<%=s[i]%>');">Paid</a>
								</div>



							</div>
						</div>

						<%
							}

								} catch (JSONException e) {

								}
								session.setAttribute("instrumentlist", s);
							}
						%>
					</div>

				</div>
			</div>
		</div>
		<br class="clear" />
	</div>
	<%@include file="footer.jsp"%>


	<script>
		$("document").ready(function() {
			$('#load_nots').load('record_count.jsp');
/*
			var auto_refresh = setInterval(function() {
				$('#load_nots').load('record_count.jsp').fadeIn("slow");
			}, 10000);
			*/			
		});

		function reject(id) {
			//alert(id);

			$.post("reject.jsp", {
				id : id
			}, function(data) {
				alert(data);
				$('#load_nots').load('record_count.jsp');
			});

		}
		function accept(number, amount, id) {
			//alert(id);
			$("#notid").val(id);
			$("#merchantnumber").val(number);
			$("#amount").val(amount);
			$("form#acceptance").submit();
		}
		function pay(iname) {
			//alert(id);
			$("#iname").val(iname);
			$("form#acceptance").submit();
		}
		function edit(instrumentfor, iname) {
			//alert(id);
			$("#iname").val(iname);
			$("#instrumentfor").val(instrumentfor);
			$("form#editinstrument1").submit();
		}
		function showhistory(mode, inst) {
			$("#mode").val(mode);
			$("#inst").val(inst);
			$("form#history").submit();
		}
	</script>

	<form id="editinstrument1" name="editinstrument"
		action="../InstrumentController" method="post">
		<input type="hidden" name="iname" id="iname" /> <input type="hidden"
			name="instrumentfor" id="instrumentfor" />


	</form>
	<form id="acceptance" name="acceptForm"
		action="/MMP/jsp/transaction.jsp" method="post">
		<input type="hidden" name="merchantnumber" id="merchantnumber" /> <input
			type="hidden" name="amount" id="amount" /> <input type="hidden"
			name="notid" id="notid" /> <input type="hidden" name="iname"
			id="iname" />
	</form>
	<form id="history" name="historyForm" action="/MMP/jsp/history.jsp"
		method="post">
		<input type="hidden" name="mode" id="mode" /> <input type="hidden"
			name="inst" id="inst" />
	</form>
</body>
</html>

